package org.lds.scheduled.job.worker.listener;

import lombok.RequiredArgsConstructor;
import org.lds.scheduled.job.common.model.AddJobModel;
import org.lds.scheduled.job.common.model.RemoveJobModel;
import org.lds.scheduled.job.worker.scheduler.service.SchedulerService;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class DefaultJobListener implements JobListener {
    private final SchedulerService schedulerService;

    @Override
    public void onJobAdded(AddJobModel addJobModel) {
        schedulerService.scheduleJob(addJobModel);
    }

    @Override
    public void onJobRemoved(RemoveJobModel removeJobModel) {
        schedulerService.deleteJob(removeJobModel.getName(), removeJobModel.getAppId().toString());
    }
}
